package com.pcxm.redis.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import redis.clients.jedis.Jedis;

public class RedisJava {
   public static void main(String[] args) {
      //连接本地的 Redis 服务
      Jedis jedis = new Jedis("127.0.0.1",6379);
//      //权限认证
//     jedis.auth("admin");  
      System.out.println("Connection to server sucessfully");
      //查看服务是否运行
      System.out.println("Server is running: "+jedis.ping());
      //设置 redis 字符串数据
      jedis.set("runoobkey", "Redis tutorial");
      Map<String, String> map = new HashMap<String, String>();
      map.put("song", "song");
      map.put("peng", "peng");
      map.put("cheng", "cheng");
      jedis.hmset("mmm", map);
    //存储数据到列表中
      jedis.lpush("tutorial-list", "Redis");
      jedis.lpush("tutorial-list", "Mongodb");
      jedis.lpush("tutorial-list", "Mysql");
      List<String> list = new ArrayList<String>();
      list.add("song");
      list.add("peng");
      list.add("cheng");
     // 获取存储的数据并输出
     System.out.println("Stored string in redis:: "+ jedis.keys("*"));
     System.out.println("Stored string in redis:: "+ jedis.get("runoobkey"));
     System.out.println("Stored string in redis:: "+ jedis.hgetAll("mmm"));
     System.out.println("Stored string in redis:: "+ jedis.lrange("tutorial-list", 0 ,5));
 }
}